package xuecheng.tool.nosql.redis;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;

import lombok.extern.slf4j.Slf4j;

/**
 * Redis 自动配置
 *
 * @author PengXueCheng
 * @version 1.0.0
 */
@SpringBootConfiguration
@ConditionalOnProperty(prefix = "spring.redis", name = {"host", "port"})
@Slf4j
public class CpxRedisAutoConfig {

    // @Bean
    // public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
    // StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    // // 开启事务
    // // redisTemplate.setEnableTransactionSupport(true);
    // stringRedisTemplate.setConnectionFactory(redisConnectionFactory);
    // return stringRedisTemplate;
    // }

    @Bean
    public RedisUtils redisUtils(StringRedisTemplate stringRedisTemplate) {
        RedisUtils redisUtils = new RedisUtils();
        redisUtils.setRedisTemplate(stringRedisTemplate);
        log.info("Redis 自动配置OK!!!");
        return redisUtils;
    }

}
